<!-- 自定义招投标列表项 card组件 -->
<template>
  <view>
    <!-- this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd'); -->
    <view class="list-item-box">
      <view
        class="title"
        @click="
          handleGoto(
            listItemData.id,
            listItemData.typeLabel,
            listItemData.typeColor
          )
        "
        >{{ listItemData.title }}</view
      >
      <view class="content">
        <text :class="['tip',displayType]">11111{{ listItemData.typeLabel }}</text>
        <text
          <u-icon
        <text class="tip" :style="{ background: listItemData.typeColor }">{{
          listItemData.typeLabel
        }}</u-icon></text>
        <text style="color: #3ba0fa">
          <!-- <u-icon
>>>>>>> 72b3fd4d4396c862bf0863282afad9d58f75601f
            name="map"
            color="#f33d3d"
            v-if="own_switchDict(AREA_CODES, listItemData.province) != ''"
          ></u-icon> -->
          <text v-if="own_switchDict(AREA_CODES, listItemData.province)"
            >·</text
          >
          {{ own_switchDict(AREA_CODES, listItemData.province) }}
        </text>
        <text v-if="listItemData.createTime" style="color: #999999">·</text>
        <text>{{
          this.$u.timeFormat(listItemData.createTime, 'yyyy-mm-dd')
        }}</text>
        <!-- 首页列表收藏 -->
        <text class="collect" @click="handleStarClick(listItemData)">
          <u-icon
            :name="
              listItemData.whetherToCollect === true ? 'star-fill' : 'star'
            "
            :color="listItemData.whetherToCollect === true ? 'red' : ''"
          ></u-icon>
          {{ listItemData.whetherToCollect === false ? '收藏' : '已收藏' }}
        </text>
      </view>
      <u-line class="u-line"></u-line>
    </view>
    <!-- 用来提示 -->
    <u-toast ref="uToast" />
  </view>
</template>

<script>
import { AREA_CODES, own_switchDict } from 'pages/common/Dict/index.js'

export default {
  props: {
    listItemData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      star: 'star',
      AREA_CODES,
      own_switchDict,
	  displayType:''
    }
  },
mounted() {
	switch(this.listItemData.type){
		case 74:
		this.displayType='diszbgg'
		break;
	}
},
  methods: {
    handleGoto(id, typeLabel, typeColor) {
      this.$u.route('/pages/detail/detail', { id, typeLabel, typeColor })
    },
    showToast(title, type) {
      this.$refs.uToast.show({
        title,
        type: type || 'error',
      })
    },
    async handleStarClick(item) {
      if (item.whetherToCollect === true) {
        item.whetherToCollect = false
        this.star = 'star'
      } else {
        item.whetherToCollect = true
        this.star = 'star-fill'
      }

      // 这里调用收藏接口
      const params = {
        objId: this.listItemData.id,
        objType: 19,
      }
      // 如果是收藏
      if (this.star === 'star-fill') {
        const { code, message } = await this.$u.post(
          '/collectionRecord/add',
          params
        )
        if (code === 200) {
          this.showToast('收藏成功', 'success')
          this.$emit('upDatelList')
        } else {
          this.showToast(message || '服务异常')
        }
      } else {
        const { code, message } = await this.$u.delete(
          '/collectionRecord/cancelCollect',
          params
        )
        if (code === 200) {
          this.showToast('取消收藏成功', 'success')
          this.$emit('upDatelList')
        } else {
          this.showToast(message || '服务异常')
        }
      }
    },
  },
  mounted() {
    console.log('listItemData ===>', this.listItemData)
  },
}
</script>

<style lang="scss">
.list-item-box {
  padding: 0 40rpx;
  margin-bottom: 16rpx;
  .title {
    color: $baseTitleColor;
    font-size: 32rpx;
    font-weight: 500;
    @include onLineEllipsis(100%);
  }
  .content {
    background: #fff;
    margin: 10px 0;
    margin-bottom: 26rpx;
    text {
      position: relative;
      color: $baseColor;
      margin-right: 14rpx;
      font-size: 22rpx;
    }
    .tip {
      width: 120rpx;
      height: 44rpx;
      padding: 10rpx;
      color: #fff;
      border-radius: 6rpx;
    }
    .collect {
      font-size: 26rpx;
      position: absolute;
      right: 20rpx;
      color: #f33d3d;
    }
  }
  .diszbgg{
	  width: 750px;
	  height: 1724px;
	  background: #F9F9F9;
	  .typeLabel{
		  width: 101px;
		  height: 23px;
		  font-size: 24px;
		  font-weight: 400;
		  color: #FFFFFF;
		  line-height: 34px;
	  }
  }
}
</style>
